home *** CD-ROM | disk | FTP | other *** search
/ One Click 14 / OneClick14.iso / Ferramentas / Convert XLS to Pdf / xls2pdf_setup.exe / {app} / lib / gs_epsf.ps < prev    next >
Encoding:
Text File  |  2002-11-21  |  7.5 KB  |  251 lines

  1. %    Copyright (C) 1989, 1996, 2002 Aladdin Enterprises.  All rights reserved.
  2. % This software is provided AS-IS with no warranty, either express or
  3. % implied.
  4. % This software is distributed under license and may not be copied,
  5. % modified or distributed except as expressly authorized under the terms
  6. % of the license contained in the file LICENSE in this distribution.
  7. % For more information about licensing, please refer to
  8. % http://www.ghostscript.com/licensing/. For information on
  9. % commercial licensing, go to http://www.artifex.com/licensing/ or
  10. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. % San Rafael, CA  94903, U.S.A., +1(415)492-9861.
  12.  
  13. % $Id: gs_epsf.ps,v 1.11 2002/11/21 09:40:06 ghostgum Exp $
  14. % Allow the interpreter to encapsulate EPS files, to recognize MS-DOS 
  15. % EPSF file headers, and skip to the PostScript section of the file.
  16.  
  17. % Encapsulate EPS files and optionally resize page or rescale image.
  18. % To display an EPS file cropped to the bounding box:
  19. %  gs -dEPSCrop file.eps
  20. % To display an EPS file scaled to fit the page:
  21. %  gs -dEPSFitPage file.eps
  22. % To display a file without EPS encapsulation:
  23. %  gs -dNOEPS file.ps
  24.  
  25. % When starting to process an EPS file, state is 0.
  26. % After %%BoundingBox processed, state is 1.
  27. % After %%HiResBoundingBox processed, state is 2.
  28. % After %%EndComments processed, state is 3.
  29. /EPSBoundingBoxState 3 def
  30. /EPSBoundingBoxSetState {
  31.   //systemdict /EPSBoundingBoxState 3 -1 roll .forceput
  32. } .bind odef % .forceput must be bound and hidden
  33.  
  34. % Parse 4 numbers for a bounding box
  35. /EPSBoundingBoxParse { % (llx lly urx ury) -- llx lly urx ury true OR false
  36.     mark exch
  37.     token {exch token {exch token {exch token {exch pop} if} if} if} if
  38.     counttomark
  39.     4 eq {
  40.       5 -1 roll pop % remove mark
  41.       true
  42.     } {
  43.       cleartomark false
  44.     } ifelse
  45. } bind def
  46.  
  47. % Rescale and translate to fit the BoundingBox on the page
  48. /EPSBoundingBoxFitPage { % llx lly urx ury --
  49.   DEBUG { (gs_epsf.ps: Rescaling EPS to fit page\n) print flush } if
  50.   clippath pathbbox newpath
  51.   % translate to new origin at lower left of clippath
  52.   3 index 3 index translate
  53.   % calculate scale to fit smaller of width or height
  54.   exch 4 -1 roll sub 3 1 roll exch sub 
  55.   4 2 roll 5 index 5 index 4 2 roll
  56.   exch 4 -1 roll sub 3 1 roll exch sub 
  57.   4 2 roll
  58.   exch 4 -1 roll div 3 1 roll exch div
  59.   1 index 1 index lt {pop}{exch pop} ifelse
  60.   dup scale
  61.   % translate to EPS -llx,-lly
  62.   exch neg exch neg translate
  63. } bind def
  64.  
  65. % Crop the page to the BoundingBox
  66. /EPSBoundingBoxCrop { % llx lly urx ury --
  67.   DEBUG { 
  68.     (gs_epsf.ps: Setting pagesize from EPS bounding box\n) print flush 
  69.   } if
  70.   exch 3 index sub exch 2 index sub % stack: llx lly urx-llx ury-lly
  71.   << /PageSize [ 5 -2 roll ] >> setpagedevice
  72.   neg exch neg exch translate
  73. } bind def
  74.  
  75.  
  76. /EPSBoundingBoxProcess { % (llx lly urx ury) state --
  77.   //systemdict /EPSBoundingBoxState get 1 index lt {
  78.     exch EPSBoundingBoxParse 
  79.     {
  80.       //systemdict /EPSCrop known {
  81.         EPSBoundingBoxCrop
  82.       } {
  83.         //systemdict /EPSFitPage known {
  84.           EPSBoundingBoxFitPage
  85.     } {
  86.       % Warn if some of the EPS file will be clipped
  87.       clippath pathbbox newpath
  88.       { % context for exit
  89.         5 -1 roll lt { 6 { pop } repeat true exit } if
  90.         4 -1 roll lt { 4 { pop } repeat true exit } if
  91.         3 -1 roll gt { 2 { pop } repeat true exit } if
  92.         exch gt { true exit } if
  93.         false exit
  94.       } loop
  95.       QUIET not and {
  96.         (\n   **** Warning: Some of the BoundingBox for the EPS file will be clipped.) =
  97.         (                 Use -dEPSCrop or -dEPSFitPage to avoid clipping.\n) =
  98.         flush
  99.       } if
  100.     } ifelse
  101.       } ifelse
  102.       EPSBoundingBoxSetState
  103.     } {
  104.       pop % state
  105.     } ifelse
  106.   } {
  107.     pop pop
  108.   } ifelse
  109. } bind def
  110.  
  111. /ProcessEPSComment { % file comment --  file comment
  112.   //systemdict /EPSBoundingBoxState get 3 lt {
  113.     dup
  114.     (%%EndComments) anchorsearch {
  115.       pop pop
  116.       % ignore any following bounding boxes
  117.       3 EPSBoundingBoxSetState
  118.     } {
  119.       (%%BoundingBox:) anchorsearch {
  120.     pop 
  121.     DEBUG { (gs_epsf.ps: found %%BoundingBox\n) print flush } if
  122.     1 EPSBoundingBoxProcess
  123.       } {
  124.     (%%HiResBoundingBox:) anchorsearch {
  125.       pop 
  126.       DEBUG { (gs_epsf.ps: found %%HiResBoundingBox\n) print flush } if
  127.     2 EPSBoundingBoxProcess
  128.     } { 
  129.       pop % Not interested in this DSC comment
  130.     } ifelse
  131.       } ifelse
  132.     } ifelse
  133.   } if
  134. } bind def
  135.  
  136. % Install EPS handler for DSC comments, which we do later
  137. /EPSBoundingBoxInit {
  138.   systemdict /NOEPS known not {
  139.     % Merge ProcessEPSComment with existing handler
  140.     /ProcessEPSComment load /exec load
  141.     currentuserparams /ProcessDSCComment get 
  142.     dup null eq {pop {pop pop}} if /exec load
  143.     4 array astore cvx readonly
  144.     << /ProcessDSCComment 3 -1 roll >> setuserparams
  145.   } if
  146. } bind def
  147.  
  148. /.runNoEPS /run load def
  149.  
  150. /.runEPS { % file OR string --
  151.   /runEPS_save save def
  152.   /runEPS_dict_count countdictstack def
  153.   /runEPS_op_count count 2 sub def
  154.   /runEPS_page_count currentpagedevice /PageCount get def 
  155.   0 EPSBoundingBoxSetState
  156.   .runNoEPS
  157.   currentpagedevice /PageCount get runEPS_page_count sub 0 eq { showpage } if
  158.   count runEPS_op_count sub {pop} repeat
  159.   countdictstack runEPS_dict_count sub {end} repeat
  160.   runEPS_save restore
  161. } bind def
  162.  
  163. /run { % file OR string --
  164.   dup type /filetype ne { (r) file } if
  165.   dup (%!PS-Adobe-) .peekstring {
  166.     (%!PS-Adobe-) eq {
  167.       dup (%!PS-Adobe-X.X EPSF-X.X) .peekstring {
  168.       (EPSF) search {
  169.         pop pop pop
  170.         DEBUG {(runEPS: Found EPS\n) print flush} if
  171.         systemdict /NOEPS known {
  172.           cvx .runNoEPS
  173.         } {
  174.           cvx .runEPS
  175.         } ifelse
  176.       } {
  177.         DEBUG {(runEPS: Normal DSC\n) print flush} if
  178.         pop
  179.           cvx .runNoEPS
  180.  
  181.       } ifelse
  182.       } {
  183.         DEBUG {(runEPS: Short DSC\n) print flush} if
  184.       pop
  185.         cvx .runNoEPS
  186.       } ifelse
  187.     } {
  188.       DEBUG {(runEPS: Not DSC\n) print flush} if
  189.       cvx .runNoEPS
  190.     } ifelse
  191.   } {
  192.     DEBUG {(runEPS: Short non-DSC\n) print flush} if
  193.     pop
  194.     cvx .runNoEPS
  195.   } ifelse
  196. } bind odef
  197.  
  198.  
  199. % Handle DOS EPS files.
  200.  
  201. /.runnoepsf /run load def
  202. /.epsfheader <C5D0D3C6> def
  203. /run
  204.  { dup type /filetype ne { (r) file } if
  205.         % Check for MS-DOS EPSF file (see Red Book p. 729).
  206.    true exch 0 1 3
  207.     {        % Stack: true file index
  208.       1 index read dup { pop dup .epsfheader 3 index get eq } if
  209.        { pop pop }    % if matched, don't need the character
  210.        {    % unread characters (wasn't EPSF)
  211.      2 index exch unread     % unread mismatch character
  212.      dup {   % loop unreading backwards in .epsfheader
  213.        1 sub dup .epsfheader exch get 2 index exch unread
  214.      } repeat pop
  215.      exch not exch exit    % change true to false
  216.        }
  217.       ifelse
  218.     }
  219.    for exch    % Stack: file true/false
  220.     {        % This block is executed if the file is MS-DOS EPSF.
  221.         % Build up the little-endian byte offset and length.
  222.       2
  223.     { 1 0 4
  224.        { 2 index read not { pop exit } if % if EOF, let error happen
  225.          2 index mul add exch 256 mul exch
  226.        }
  227.       repeat exch pop exch
  228.     }
  229.       repeat
  230.         % Stack: offset length file
  231.         % Use flushfile to skip quickly to the start of the
  232.         % PostScript section.
  233.       dup 4 -1 roll 12 sub () /SubFileDecode filter flushfile
  234.         % Now interpret the PostScript.
  235.       exch () /SubFileDecode filter cvx run
  236.     }
  237.     { .runnoepsf
  238.     }
  239.    ifelse
  240.  } odef
  241.  
  242. % rebind .runstdin to use redefined run
  243. userdict begin
  244. /.runstdin {
  245.   { (%stdin) run } execute0
  246. } bind def
  247. end
  248.